package com.bbjob.controller;

import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.bbjob.dto.Result;
import com.bbjob.model.SysOrganizationStu;
import com.bbjob.query.QueryExaminee;
import com.bbjob.service.IExamineeService;

@Api(tags = "examineeApi", description = "考生管理")
@RestController
@RequestMapping(path = "examinee", produces = "application/json;charset=utf-8")
public class ExamineeController {
	
	@Resource
	private IExamineeService examineeService;
	
	@ApiOperation(value="考生录入", notes="考生录入")
	@ApiImplicitParam(name="stu", value="考生录入", required=true, dataType="SysOrganizationStu")
	@RequestMapping(value="entry", method=RequestMethod.POST)
	public Result entryExaminee(@RequestBody SysOrganizationStu stu) {
		
		
		return examineeService.entryInfo(stu);
	}

	
	@ApiOperation(value="考生导入", notes="考生导入")
	@RequestMapping(value="import", method=RequestMethod.POST)
	public Map<String, Object> importExaminee(HttpServletRequest request,  @RequestParam(value="file", required=false) MultipartFile multipartFile) {
		
		Map<String, Object> returnMap = examineeService.importExaminee(multipartFile, request);
		
		return returnMap;
	}

	@ApiOperation(value="考生列表", notes="考生列表")
	@ApiImplicitParam(name="examinee", value="考生信息", required=true, dataType="QueryExaminee")
	@RequestMapping(value="list", method=RequestMethod.POST)
	public Result list(@RequestBody QueryExaminee examinee) {
		
		// List<SysOrganizationStu> data = examineeService.selectByParams(examinee);
		
		// PageInfo<SysOrganizationStu> pageInfo = ; //new PageInfo<SysOrganizationStu>(data);
		return examineeService.selectByParams(examinee);
	}
	
	@ApiOperation(value="考生信息", notes="考生信息")
	@ApiImplicitParam(name="id", value="考生信息id", required=true, dataType="Integer", paramType="path")
	@RequestMapping(value="get/{id}", method=RequestMethod.GET)
	public Result get(@PathVariable("id")Integer id) {
		
		SysOrganizationStu ret = examineeService.selectByPrimaryKey(id);
		
		return new Result(ret);
	}
	
	@ApiOperation(value="修改考生信息", notes="修改考生信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name="id", value="考生信息id", required=true, dataType="Integer", paramType="path"),
			@ApiImplicitParam(name="stu", value="考生信息", required=true, dataType="SysOrganizationStu")	
	})
	@RequestMapping(value="edit/{id}", method=RequestMethod.POST)
	public Result edit(@PathVariable("id")Integer id, @RequestBody SysOrganizationStu stu) {
		
		stu.setId(id);
		
		return examineeService.updateStudent(stu, id);
	}
	
	@ApiOperation(value="删除考生信息", notes="删除考生信息")
	@ApiImplicitParam(name="id", value="考生信息id", required=true, dataType="Integer", paramType="path")
	@RequestMapping(value="del/{id}", method=RequestMethod.GET)
	public Result del(@PathVariable("id")Integer id) {
		
		examineeService.delById(id);
		
		return new Result();
	}
	
}
